import { request } from "../../request/index.js"
import regeneratorRuntime from '../../lib/runtime/runtime'
import {login} from "../../utils/asyncWx.js"

Page({
async  handleGetUserInfo(e){
   try {
      // console.log(e);
    // 1 获取用户信息
    const {encryptedData,rawData,iv,signature}=e.detail;
    // 2 获取小程序登录后的CODE
    const {code}= await login();
      
    // 3 发送请求 获取token
    const loginParams={encryptedData,rawData,iv,signature,code};

    console.log(loginParams);
    const {token}=await request({url:"/users/wxlogin",data:loginParams,method:"POST"});

    wx.setStorageSync("token", token);
      
    wx.navigateBack({
      delta: 1
    });
   } catch (error) {
     console.log(error);
   }
      

  }
})